<?php
    session_start();
    include("language.php");
    include('database.php');
    
    $_SESSION['curPage'] = 'addTickets.php';
    
    $info = '';
    
    if(isset($_SESSION['connected']) AND $_SESSION['connected'])
    {
        if($_SESSION['access'] != 10)
        {
          header("Location: error.php");
        }
        else
        {

            if(isset($_POST['pseudo'])and isset($_POST['nbr']) )
            {
             $variable = $db->exec("UPDATE user SET tickets = tickets + ".$_POST['nbr']. " WHERE battletag=\"" . $_POST['pseudo'] . "\""); 
               
             if($variable == 1)
             {
                $db->exec("UPDATE user SET soldTickets = soldTickets + " . $_POST['nbr'] . " WHERE id=" . $_SESSION['id']);
                $info = $_POST['nbr'] . ' tickets ont été ajoutés à ' . $_POST['pseudo'];
             }
             else
             {
                 $info = "Le battletag n'est pas dans la base de donnée";                 
             }
           }     
        }
    }
    else header("Location: error.php");
?>
<!DOCTYPE html>
<html>
    <head>
            <meta charset="utf-8" />
            <link rel="stylesheet" href="style.css" />
    </head>
    <body>
        
        <div class="d_body">
            <?php include('header.php'); ?>
             
        <div class="d_menuBar">
            <ul class="menuBarTable">
                <li><a href="home.php">Acceuil</a></li>
                <li><a href="listMember.php">Liste des membres</a></li>
                <li><a href="addTickets.php">Ajout tickets</a></li>
                <li><a href="idTicketByDraw.php">Liste Ticket</a></li>
            </ul>
        
            </div>
            <br><br><br><br><br>
            
           <?php
           $var = 0;
           $pseudo= '';

            echo '<center><form method="post" action="addTickets.php">
            <table class="listMember">
             <th class="td_listerMember">Battletag</th><th class="td_listerMember">Nombre Ticket</th><th class="td_listerMember">Ajouter</th><tr>';
     
             echo '<td><input type=text name="pseudo" value='.$pseudo.'></td>';
             echo '<td><input type=text name="nbr" value='.$var.'></td>';
             echo '<td class="td_listerMember"><input type=submit name="id" value="Ajouter"></input></td></tr>';
            
             echo '</tr></table></form></center>';    
             
             echo '<p>' . $info . '</p>'
           ?>
            
       </div>
    </body>
</html>
        